<?php

namespace app\common\model;

use traits\model\SoftDelete;

class Course extends Model
{

    use SoftDelete;


    // 表名
    protected $name = 'course';


    // 追加属性
    protected $append = [
        'user_star',
        'user_buy',
    ];

    public function getUserStarAttr($value, $data)
    {
        return $value ?: 0;
    }

    public function getUserBuyAttr($value, $data)
    {
        return $value ?: 0;
    }

    public function category()
    {
        return $this->belongsTo(\app\common\model\course\Category::class, 'course_category_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
